var $;
layui.use(["jquery", "laydate", "form", "upload",'element'], function () {
    $ = layui.jquery;
    var laydate = layui.laydate;
    var form = layui.form;
    var upload = layui.upload;
    var element = layui.element;
    var createId = localStorage.getItem('createId');
    //获取用户信息
    getuser();

    function getuser() {
        $.ajax({
            url: "/login/getUser",
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#uname").val(data.data.account);
                localStorage.setItem("account", data.data.account);
                localStorage.setItem("password", data.data.password);
                $("#email").val(data.data.email);
            }
        });
    }

    //vue校验
    var vm = new Vue({
        el: '#box',
        data: {
            one: "",
            two: ""
        },
        methods: {
            update() {
                var password = $("#upassword1").val();
                $.ajax({
                    url: "/login/updateUser",
                    type: "post",
                    data: {
                        "userId":createId ,
                        "password": password,
                        "acatarUrl": url
                    },
                    dataType: "json",
                    success: function (data) {
                        console.log(data.data);
                        if (data.data == true) {
                            layer.alert("修改成功,建议您重新登录");
                            $("#upassword1").val("");
                            $("#upassword2").val("");
                            parent.$('#acatarUrl').attr('src',url);
                        } else {
                            layer.alert("修改失败");
                        }
                    }
                });
            }
        },
        watch: {
            one(newVal, oldVal) {

            },
            two(newVal, oldVal) {
                if (this.one == newVal) {
                    $("#update").removeClass("dis");
                } else {
                    $("#update").addClass("dis");
                }
            }
        }
    });
    var acatarUrl = localStorage.getItem('acatarUrl');
    $('#acatarUrl').attr('src', acatarUrl);
    var url;
    //头像上传
    upload.render({
        elem:'#acatarUrl',
        url:'/upload/uploadFile',
        field: "files",
        accept: "images",
        size:2048,
        done:function (res,index,upload) {
            url = res.data.path;
            $('#acatarUrl').attr('src',url);
        },
        progress: function(n, elem, res, index){
            var percent = n + '%' //获取进度百分比
            element.progress('demo', percent); //可配合 layui 进度条元素使用
            element.progress('demo-'+ index, n + '%'); //进度条
        }
        
    });
});
//刷新
function Refresh() {
    location.reload();
}
//跳转
function goBack() {
    //通过页面查找iframe
    parent.$('#recordLog').val($('#accSet').text());
    parent.before();
    return false;
}
